// 用来创建为Count组件服务的reducer，reducer的本质就是一个函数
// reducer函数会接收到两个参数，分别为之前的状态preState，动作对象action
import { INCREMENT, DECREMENT } from '../constant';


const initState = 0;
export default function countReducer(preState = initState, action) { 
  const { type, data } = action;
  switch (type) { 
    case INCREMENT:
      return preState + data;
    case DECREMENT:
      return preState - data;
    default:
      return preState;
  }
}